﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Data;
using System.Data.Odbc;
using System.Runtime.Remoting.Messaging;

namespace addemployeerecordcodefile
{
    class addemployee
    {
        OdbcConnection donconnection = new OdbcConnection();
        OdbcDataAdapter donadapter = new OdbcDataAdapter();
        DataTable dondatatable = new DataTable();
        string pth = Environment.CurrentDirectory;
        public void dbConnect()
        {
            donconnection.ConnectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)}" +
                ";DBQ=" + pth + "\\Database\\BenguetCorpEmployeeDatabase.accdb" +
                ";UID=" +
                ";PWD=";
            donconnection.Open();
        }
        public void dbQuery(string donSql)
        {
            donadapter.SelectCommand = new OdbcCommand(donSql, donconnection);
            dondatatable.Reset();
            dondatatable.Clear();
            donadapter.Fill(dondatatable);
            donconnection.Close();
        }
        public void donCommit()
        {
            OdbcCommandBuilder donconnectionb = new OdbcCommandBuilder(donadapter);

            try
            {
                donadapter.Update(dondatatable);
            }
            catch { }

        }
        public DataTable donResult
        {
            get { return dondatatable; }
        }



        //adding profile asynchronously
        public void donAdd(string empnum, string estat, string ename, string edept, string epos, string egender, string econtact, 
            string epresadd, string epermadd, string ehyt, string eweyt, string emarital, string ebday, string eage, string etin,
            string esss, string ephil, string epag, string eeducattain, string edatehired, string efaname, string efaadd, string efanum,
            string emoname, string emoadd, string emonum, string espousename, string espouseoccu, string eboardexam, string ecsc,
            string edriver, string eprc, string etesda, string eothers, string findsurname)
        {
            DataRow dondr = dondatatable.NewRow();
            dondr["fEmployeeNumber"] = empnum;
            dondr["fEmployeeStatus"] = estat;
            dondr["fEmployeeName"] = ename;
            
            dondr["fDepartment"] = edept;
            dondr["fPosition"] = epos;
            dondr["fGender"] = egender;
            dondr["fContact"] = econtact;
            dondr["fPresentAddress"] = epresadd;
            dondr["fPermanentAddress"] = epermadd;
            dondr["fHeight"] = ehyt;
            dondr["fWeight"] = eweyt;
            dondr["fMaritalStatus"] = emarital;
            dondr["fBirthdate"] = ebday;
            dondr["fAge"] = eage;
            dondr["fTIN"] = etin;
            dondr["fSSS"] = esss;
            dondr["fPHILHEALTH"] = ephil;
            dondr["fPagibig"] = epag;
            dondr["fEducAttain"] = eeducattain;
            dondr["fDateHired"] = edatehired;
            dondr["fFatherName"] = efaname;
            dondr["fFatherAddress"] = efaadd;
            dondr["fFatherNumber"] = efanum;
            dondr["fMotherName"] = emoname;
            dondr["fMotherAddress"] = emoadd;
            dondr["fMotherNumber"] = emonum;
            dondr["fSpouseName"] = espousename;
            dondr["fSpouseOccupation"] = espouseoccu;

            dondr["fBoardExamRating"] = eboardexam;
            dondr["fCSCEligibility"] = ecsc;
            dondr["fDriversLicense"] = edriver;
            dondr["fPRCNumber"] = eprc;
            dondr["fTesdaNCTitle"] = etesda;
            dondr["fOthers"] = eothers;
            dondr["fSurname"] = findsurname;

            dondatatable.Rows.Add(dondr);
        }
        delegate void addprofile(string empnum, string estat, string ename, string edept, string epos, string egender, string econtact,
            string epresadd, string epermadd, string ehyt, string eweyt, string emarital, string ebday, string eage, string etin,
            string esss, string ephil, string epag, string eeducattain, string edatehired, string efaname, string efaadd, string efanum,
            string emoname, string emoadd, string emonum, string espousename, string espouseoccu, string eboardexam, string ecsc,
            string edriver, string eprc, string etesda, string eothers, string findsurname);
        
        public void asyncaddprofile(string empnum, string estat, string ename, string edept, string epos, string egender, string econtact, 
            string epresadd, string epermadd, string ehyt, string eweyt, string emarital, string ebday, string eage, string etin,
            string esss, string ephil, string epag, string eeducattain, string edatehired, string efaname, string efaadd, string efanum,
            string emoname, string emoadd, string emonum, string espousename, string espouseoccu, string eboardexam, string ecsc,
            string edriver, string eprc, string etesda, string eothers, string findsurname)
        {
            addprofile ap = new addprofile(donAdd);
            AsyncCallback ac = new AsyncCallback(cbaddprofile);
            IAsyncResult ar = ap.BeginInvoke(empnum,estat,ename,edept,epos,egender,econtact,epresadd,epermadd,ehyt,eweyt,emarital,
                ebday,eage,etin,esss,ephil,epag,eeducattain,edatehired,efaname,efaadd,efanum,emoname,emoadd,emonum,espousename,espouseoccu,eboardexam,
                ecsc,edriver,eprc,etesda,eothers,findsurname,ac, null);
        }
        void cbaddprofile(IAsyncResult ar)
        {
            addprofile ap = (addprofile)((AsyncResult)ar).AsyncDelegate;
            ap.EndInvoke(ar);
            onaddcompleted(null, null);
        }
        public event EventHandler addcompleted;
        protected virtual void onaddcompleted(object sender, EventArgs e)
        {
            if (addcompleted != null) addcompleted(sender, e);
        }
        //end of adding asynchronously

        
    }
}